package com.peng.leetcode.search;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * TopKFrequent
 *
 *@author lupeng
 *Created on 2021-05-20
 */
public class TopKFrequent {

    public static void main(String[] args) {

    }

    public List<String> topKFrequent(String[] words, int k) {
        Map<String, Tuple> countMap = new HashMap<>();
        for (String word : words) {
            countMap.putIfAbsent(word, new Tuple(word, 0));
            countMap.computeIfPresent(word, (key, v) -> {
                v.setCount(v.getCount() + 1);
                return v;
            });
        }
        List<Tuple> tuples = countMap.entrySet()
                .stream()
                .map(Map.Entry::getValue)
                .collect(Collectors.toList());

        return null;
    }

    static class Tuple {
        private String word;
        private Integer count;

        public Tuple(String word, Integer count) {
            this.word = word;
            this.count = count;
        }

        public String getWord() {
            return word;
        }

        public void setWord(String word) {
            this.word = word;
        }

        public Integer getCount() {
            return count;
        }

        public void setCount(Integer count) {
            this.count = count;
        }
    }

}
